package com.music.mysongs.utils

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.util.Log
import android.widget.Toast
import java.util.*

const val Tag: String = "MySongs"

object ActivityCollector {
    private val activities = ArrayList<Activity>()
    fun addActivity(activity: Activity) {
        activities.add(activity)
    }

    fun removeActivity(activity: Activity) {
        activities.remove(activity)
    }

    fun finishAll() {
        for (activity in activities) {
            if (!activity.isFinishing) {
                activity.finish()
            }
        }
        activities.clear()
    }
}

fun myToast(cxt: Context, msg: String, type: Int = 0) {
    val duration = if (type == 1) {
        Toast.LENGTH_LONG
    } else {
        Toast.LENGTH_SHORT
    }
    Toast.makeText(cxt, msg, duration).show()
}

fun myToastWithoutCxt(msg: String, type: Int = 0) {
    val duration = if (type == 1) {
        Toast.LENGTH_LONG
    } else {
        Toast.LENGTH_SHORT
    }
    Toast.makeText(MyApplication.context, msg, duration).show()
}

fun myGoActivity(cxt: Context, cls: Class<*>) {
    val intentObj = Intent(cxt, cls)
    cxt.startActivity(intentObj)
}

fun myLog(msg: String) {
    Log.i(Tag, msg)
}